# -*- coding: utf-8 -*-
"""
Created on Wed Apr  3 10:26:41 2024

@author: 刘翼
"""

import cv2
import numpy as np
from matplotlib import pyplot as plt
# 开运算
img = cv2.imread(r"C:\Users\Public\opencv\Figure\contour_noise.png",0)
kernel = np.ones((3,3),np.uint8)
opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)

plt.figure(' MORPH_OPEN ',figsize=(8,8))
plt.subplot(221)
plt.title('origin image')
plt.imshow(img,plt.cm.gray)
plt.axis('off')
plt.subplot(222)
plt.title(' opening image')
plt.imshow(opening,plt.cm.gray)
plt.axis('off')

# 闭运算
closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel)

plt.figure('MORPH_CLOSE ',figsize=(8,8))
plt.subplot(223)
plt.title('origin image')
plt.imshow(img,plt.cm.gray)
plt.axis('off')
plt.subplot(224)
plt.title('closing image')
plt.imshow(closing,plt.cm.gray)
plt.axis('off')
